package com.wang.rabbitmqstudy.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

@Component
public class AutoDeleteQueueHandler {

    @RabbitListener(queues = {"argumentsAutoDeleteQueue"})
    @RabbitHandler
    public void execute(Channel channel, Message message) throws InterruptedException, IOException {
        System.out.println(new String(message.getBody()));
        // 手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        // 休眠100s，这个时候我手动停止服务器，队列被删除了
        TimeUnit.SECONDS.sleep(100);
    }
}
